package com.springcloud.gateway.util;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

/**
 * @version V1.0
 * @Author 宋聚智
 * @Date 2019/11/1 9:46
 * @description
 * @Modify By：
 * @ModifyTime： 2019/11/1
 * @Modify marker：
 **/
public class JwtUtil {
    public static String SIGN_KEY ="BladeX";
    public static String BEARER="bearer";
    public static Integer AUTH_LENGTH=7;
    public static String  BASE64_SECURIRY;
    public JwtUtil(){}


    public static String getToken(String auth){
        if(auth!=null && auth.length()>AUTH_LENGTH){
            String headStr= auth.substring(0,6).toLowerCase();
            if(headStr.compareTo(BEARER)==0){
                auth=auth.substring(7);
                return auth;
            }
        }
        return null;
    }

    public static Claims parseJWT(String jsonWebToken){
        try{
            return Jwts.parser().setSigningKey(Base64.getDecoder()
                    .decode(BASE64_SECURIRY)).parseClaimsJws(jsonWebToken).getBody();
        }catch (Exception var2){
            return  null;
        }
    }
    static {
        BASE64_SECURIRY=Base64.getEncoder().encodeToString(SIGN_KEY.getBytes(StandardCharsets.UTF_8));
    }






}
